#include "ICMPv4_ERROR.h"
#include "ICMPv4config.h"
#include "AbstractionAPI.h"
#include <stdio.h>
#include <string.h>
#include "TestabilityProtocol_api.h"
#include "TestabilityProtocol_Intern.h"

#define MAC "62:66:64:61:AA:17"
#define IP_DUT "192.168.1.211" //"10.98.4.23"
#define IP_TESTER "192.168.1.175"
#define IPV4_ADDRESS_SIZE 4U  /*  4 bytes */
typedef unsigned short int uint16;
typedef unsigned char uint8;
void stoiIP(const char *in_s, uint8_t *out_ip) 
{
    char temp_c;
    uint8_t octet_i = 0;
    uint8_t octet_p = 0;
    for (uint8_t i = 0; i < strlen(in_s); i++ ) 
    {
        temp_c = in_s[i];
        if (temp_c == '.') 
        {
            out_ip[octet_p] = octet_i;
            octet_i = 0;
            octet_p += 1;
        } 
        else 
        {
            octet_i *= 10;
            octet_i += temp_c - '0';
        }
    }
    out_ip[octet_p] = octet_i;
}



int main()
{
	//Configure Network API
    Net_API_config_t NetAPIConfig; 
    strcpy(NetAPIConfig.S_interface, "enp0s3");
    strcpy(NetAPIConfig.S_DUT_HW_Address,MAC);
    strcpy(NetAPIConfig.S_DUT_IP_Address,IP_DUT);
    strcpy(NetAPIConfig.S_Tester_HW_Address, "6C:4B:90:79:0E:D1");
    strcpy(NetAPIConfig.S_Tester_IP_Address, "192.168.1.175");
    Set_Network_Abstration_API_Config(NetAPIConfig);
	
    ICMPv4_config_t conf;
    strcpy(conf.DUT_IP, "192.168.1.211");
    strcpy(conf.TESTER_IP, "192.168.1.175" );
    conf.INVALID_ICMP_TYPE = 44;
    conf.LISTEN_TIME = 3;
    Set_ICMPv4_Config(conf);

	 ip4addr ipv4;
    ipv4.dataLength = 4;
    stoiIP(IP_DUT, ipv4.Data);
	
    TP_OpenControlChannel(ipv4, 56000);
	
	ICMPv4_ERROR_02();
	ICMPv4_ERROR_03();	
	ICMPv4_ERROR_04();
	ICMPv4_ERROR_05();
	TP_CloseControlChannel();

	return 0;
}

